package com.awspaas.user.apps.processforsap.model;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;
import com.alipay.sofa.common.profile.StringUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class MessageHeader {
    /**
     * SAP通用字段
     */
    String Interface_ID;
    String UUID;
    String MessageId;
    String Sender;
    String Receiver;
    String SendDate;
    String SendTime;
    String DisId;
    String LogId;
    BO configBo;
    List<BO> girdConfigBo;

    /**
     * BPMBO字段
     */
    public MessageHeader(String interfaceId, String uuid, String messageId, String disId) {
        SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HHmmss");
        Date nowDate = new Date();
        if (StringUtil.isEmpty(interfaceId)) {
            throw new BPMNError("0331", "参数interfaceId【接口编码】不允许为空！");
        } else {
            BO bo = SDK.getBOAPI().query("BO_EU_SERVICE_INTERFACE_CONFIG").addQuery("INTERFACE_NO=", interfaceId).detail();
            List<BO> girdBo = SDK.getBOAPI().query("BO_EU_SERVICE_INTERFACE_LIST").bindId(bo.getBindId()).list();
            String result []= interfaceId.split("&");
            interfaceId = result[0];
            if (bo == null) {
                throw new BPMNError("0331", "未找到对应接口表的数据，请核查配置信息！");
            } else {
                //发送方
                String send = bo.getString("SEND");
                //接收方
                String receive = bo.getString("RECEIVE");
                this.Interface_ID = interfaceId;
                this.Sender = send;
                this.Receiver = receive;
                this.configBo = bo;
                this.girdConfigBo = girdBo;
                this.UUID = uuid;
                this.MessageId = messageId;
                this.DisId = disId;
                this.SendDate = dataFormat.format(nowDate);
                this.SendTime = timeFormat.format(nowDate);
            }
        }
    }

    public String getLogId() {
        return LogId;
    }

    public String getInterface_ID() {
        return Interface_ID;
    }

    public String getUUID() {
        return UUID;
    }

    public String getMessageId() {
        return MessageId;
    }

    public String getSender() {
        return Sender;
    }

    public String getReceiver() {
        return Receiver;
    }

    public String getSendDate() {
        return SendDate;
    }

    public String getSendTime() {
        return SendTime;
    }

    public String getDisId() {
        return DisId;
    }

    public BO getConfigBo() {
        return configBo;
    }

    public List<BO> getGirdConfigBo() {
        return girdConfigBo;
    }
}
